
void RCinit(void)
{
   pinMode(Chan1Pin, INPUT);
   pinMode(Chan1Pin, INPUT);
   pinMode(Chan2Pin, INPUT);
   pinMode(Chan3Pin, INPUT);
   pinMode(Chan4Pin, INPUT);
  

   attachInterrupt(Chan1Pin, handler_CH1, RISING);
   attachInterrupt(Chan2Pin, handler_CH2, CHANGE);
   attachInterrupt(Chan3Pin, handler_CH3, CHANGE);
   attachInterrupt(Chan4Pin, handler_CH4, CHANGE);
   
}
uint32 nowTimerValue,lastTimerValue;
uint32 diff;
void handler_CH1(void) {               // Measure RC sum
static int chan=0;
 toggleLED();  
 nowTimerValue= micros();
 diff=nowTimerValue-lastTimerValue;
 lastTimerValue=nowTimerValue;
 if(diff>3000)chan=0;
 else
 {
   if(900<diff&&diff<2200 && chan<8) rcValue[chan]=diff;
   chan++;
 }
     
} 

uint32 nowRxTime;
#define RxRecMaco(CH_NO)  nowRxTime=micros();\
                     if(digitalRead(Chan##CH_NO##Pin)==LOW)\
                     {                              \
                       RxChStart##CH_NO=nowRxTime;       \
                     }                             \
                    else                           \
                   {                               \
                    RxCh##CH_NO=nowRxTime-RxChStart##CH_NO;    \
                    }                              \
                    
void handler_CH2(void) 
{
  RxRecMaco(2);
   
}

void handler_CH3(void) 
{ 
 RxRecMaco(3);
}

void handler_CH4(void) 
{
   
  RxRecMaco(4);
}

 


